package com.sm.service;

import java.util.List;

import com.sm.model.Collect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sm.dao.CollectMapper;
import com.sm.model.CourseCollect;
import com.sm.model.GoodsBean;

/**
 *	收藏service
 * @author Administrator
 */
@Service
public class CollectService {
	
	@Autowired
	private CollectMapper collectMapper;
	
	/**
	 *	通过用户id查询用户的收藏的数量
	 * @param userId	用户id
	 * @return
	 */
	public int selectCollectNumber(Integer userId) {
		
		int collectNumber = collectMapper.selectCollectNumber(userId);
		return collectNumber;
	}
	
	/**
	 *	通过商品id和用户id查询该商品是否被该用户收藏
	 * @param goodsId	商品id
	 * @param userId	用户id
	 * @param 	，-1是商品，1是视频，2是幸福问答
	 * @return
	 */
	public Collect selectCollectByUserId(Integer goodsId, Integer userId) {
		int collectType = -1;//定义一个收藏内容是商品。
		return collectMapper.selectCollectByUserId(userId, goodsId, collectType);
	}
	
	/**
	 *	通过视频id和用户id查询视频收藏是否存在。
	 * @param userId
	 * @param videoCourseId
	 * @return
	 */
	public Collect selectCollectByVideoId(Integer userId, Integer videoCourseId,Integer collectType) {
		return collectMapper.selectCollectByVideoId(userId, videoCourseId, collectType);
	}
	
	public int insertSelective(Collect record){
		return collectMapper.insertSelective(record);
	}
	
	public List<GoodsBean> selectGoodsCollect(Integer userId){
    	return collectMapper.selectGoodsCollect(userId);
    }
	
	public List<CourseCollect> selectCourseCollect(Integer userId){
		return collectMapper.selectCourseCollect(userId);
    }
	
	public int deleteByPrimaryKey(Integer collectId) {
		return collectMapper.deleteByPrimaryKey(collectId);
	}
	
	public int deleteCollect(Integer[] collectIds) {
		return collectMapper.deleteCollect(collectIds);
	}
	
	public Collect selectCollectBy(Integer userId, Integer collectType, Integer courseGoodsId) {
		return collectMapper.selectCollectBy(userId, collectType, courseGoodsId);
	}

	public int cancelCollect(Integer userId, Integer collectType, Integer courseGoodsId){
		return collectMapper.cancelCollect(userId, collectType, courseGoodsId);
	}
}
